﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace OpenRPOSMetro
{
    public sealed partial class CarryOutDialog : Page
    {
        public event EventHandler CloseRequested;
        public ServiceReferenceOpenRPOS.OrderSummary orderSummary;
        public bool bUpdated = false;

        public CarryOutDialog()
        {
            this.InitializeComponent();
        }
        public void init(ServiceReferenceOpenRPOS.OrderSummary currentOrderSummary)
        {
            orderSummary = currentOrderSummary;
            // Show associated carry-out data
            cbCarryOut.IsChecked = orderSummary.col_CarryOut;
            tbCustomerName.Text = (orderSummary.col_CustomerName == null) ? "" : orderSummary.col_CustomerName;
            tbPhoneNumber.Text = (orderSummary.col_CustomerPhone == null) ? "" : orderSummary.col_CustomerPhone;
            var pane = InputPane.GetForCurrentView();
            pane.Showing += pane_Showing;
            pane.Hiding += pane_Hiding;
            //this.LayoutRoot.Margin = new Thickness(0, 100, 0, 0);
            //this.RootPanel.Margin = new Thickness(0, -400, 0, 0);
        }
        private void pane_Showing(InputPane sender, InputPaneVisibilityEventArgs e)
        {
            // Shift the dialog up...
            this.RootPanel.Margin = new Thickness(0, -1 * e.OccludedRect.Y, 0, 0);
        }
        private void pane_Hiding(InputPane sender, InputPaneVisibilityEventArgs e)
        {
            // Restore...
            this.RootPanel.Margin = new Thickness(0, 0, 0, 0);
        }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            // Update information...
            orderSummary.col_CarryOut = cbCarryOut.IsChecked==true;
            orderSummary.col_CustomerName = tbCustomerName.Text;
            orderSummary.col_CustomerPhone = tbPhoneNumber.Text;
            bUpdated = true;
            // Close the dialog
            if (this.CloseRequested != null)
            {
                this.CloseRequested(this, EventArgs.Empty);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            // Close the dialog
            if (this.CloseRequested != null)
            {
                this.CloseRequested(this, EventArgs.Empty);
            }
        }
    }
}
